package com.czone.myfacebook;

import java.io.InputStream; 

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.view.View;
import android.widget.ImageView;

public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    ImageView mImgView;
    ProfileImageData mPID;
    private static final String TAG = "DownloadImageTask";

    public DownloadImageTask(ImageView iv, ProfileImageData pID) {
        mImgView = iv;
        mPID = pID;
    }

    protected Bitmap doInBackground(String... urls) {
        CLog.i(TAG, "doInBackground E = " + urls[0]);
        
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return mIcon11;
    }

    protected void onPostExecute(Bitmap result) {
        CLog.i(TAG, "onPostExecute E");
        
        mImgView.setVisibility(View.VISIBLE);
        mImgView.setImageBitmap(result);
        if (mPID != null) {
            mPID.setBitmap(result);
        }
        mImgView = null;
    }
}
